/* jshint esversion: 6 */

const mysql = require('mysql');

//Nodejs 使用MySQL插入数据
// init db config & create mysql connection
const connection = mysql.createConnection({
    host: 'localhost',
    port: 3306,
    user: 'root',
    password: 'chendong',
    database: 'quarterReport'
});
connection.connect();

let data = {
    richText: 'auto insert by using nodejs',
    publish_author: 'lomo2017',
    beginDate: '2018-01-01',
    endDate: '2018-03-31'
};
connection.query('INSERT INTO processRiskDesc SET ?', data, function(error, results, fields) {
    if (error)
        throw (error);
    console.log(results);
    console.log(results.insertId); // 1,2 ....
});

connection.end();